<?php
namespace app\admin\model;

use think\Model;

class Brand extends Model
{


    public function getRecommendedAttr($v,$d)
    {
        $arr = [
            0=>'否',
            1=>'是'
        ];
        return $arr[$d['recommended']];
    }

    public function getIfShowAttr($v,$d)
    {
        $arr = [
            0=>'否',
            1=>'是'
        ];

        return$arr[$d['if_show']];
    }







    public function searchBrandNameAttr($q,$v,$d)
    {
        $q->where('brand_name','like',"%{$v}%");
    }


    public function searchIfShowAttr($q,$v,$d)
    {
        $q->where('if_show','in',$v);
    }


    public function searchRecommendedAttr($q,$v,$d)
    {
        $q->where('recommended','=',$v);
    }





    public function searchBrandLogoAttr($q,$v,$d)
    {
       if ($d['brand_logo']==1){
           $q->where('brand_logo','<>','');
       }
       if ($d['brand_logo']==0){
           $q->where('brand_logo','=','');
       }
    }

















    public static function getGoodsBrand($where,$all)
    {
        return Brand::table('ecm_brand')
            ->withSearch(array_keys($where),$where)
            ->order('sort_order asc')
            ->paginate(['list_rows'=>5,'query'=>$all]);
    }

}